import { doGenerateClassSystem } from '@/api/base/workCalendar/shiftSystem';
import { message } from '@/components/q-message/message';
export const useUpdate = (getData: () => void) => {
    let timer: number;
    const loadingShow = ref(false);
    const classSystemUpdate = () => {
        timer = window.setInterval(generateClassSystem, 1500);
        loadingShow.value = true;
    };

    const generateClassSystem = async () => {
        try {
            const { data } = await doGenerateClassSystem();
            if (data === false) {
                close();
                message.success('处理完成！');
                getData();
            }
        } catch (error) {
            close();
        }
    };

    const close = () => {
        clearInterval(timer);
        loadingShow.value = false;
    };

    onUnmounted(() => {
        close();
    });

    return {
        classSystemUpdate,
        loadingShow
    };
};
